package cc.yiueil.controller;

import cc.yiueil.entity.ProductEntity;
import cc.yiueil.service.ProductService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
public class ProductController {

    private final ProductService productService;

    public ProductController(ProductService productService) {
        this.productService = productService;
    }

    @GetMapping(value = "/getProduct")
    public ProductEntity getProduct(@RequestParam Long id, HttpServletRequest request) {
        System.out.println("getProduct被调用");
        String token = request.getHeader("yl-token");
        System.out.println("token:" + token);
        // 模拟接口慢响应
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        return productService.getProduct(id);
    }

}
